//
//  AppDelegate.m
//  Model
//
//  Created by apple on 2018/7/9.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "AppDelegate.h"
#import "IQKeyboardManager.h"
#import "welcomeViewController.h"
#import "WXApi.h"
#import "UMSocialWechatHandler.h"
#import "XMMovableButton.h"
@interface AppDelegate ()<WXApiDelegate>

@end

@implementation AppDelegate





- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    

    [[UMSocialManager defaultManager] setUmSocialAppkey:@"5b4ff778f43e48013d00027c"];
    /* 设置微信的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxa7930915a10d04ce" appSecret:@"b2134d0df682004375ae6952191699bc" redirectURL:@"http://mobile.umeng.com/social"];
//


    
    // Override point for customization after application launch.
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    manager.shouldResignOnTouchOutside = YES;//这个是点击空白区域键盘收缩的开关
    manager.enableAutoToolbar = NO;//这个是它自带键盘工具条开关
    self.window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
    [self.window makeKeyAndVisible];
    NSString *user_id = [PublicFunction getConfigWithKey:@"user_id"];
    if (user_id) {

        MyTabBarController *barController = [[MyTabBarController alloc] init];
        barController.view.backgroundColor = getColor(@"ffffff");

        UINavigationBar *bar = [UINavigationBar appearance];

        [bar setBackgroundImage:[UIImage imageNamed:@"bg_top"] forBarMetrics:UIBarMetricsDefault];

        [bar setShadowImage:nil];
        bar.translucent = NO;

        bar.barStyle = UIBarStyleBlackTranslucent;
        //设置显示的颜色
        bar.barTintColor = getColor(@"fe45cf");
        //设置字体颜色
        bar.tintColor = [UIColor whiteColor];
        [bar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

        self.window.rootViewController = barController;



    }else{
    
        welcomeViewController *startUpVC = [[welcomeViewController alloc]init];
        self.window.rootViewController = startUpVC;
        
    }
    
//    XMMovableButton *movableButton=[[XMMovableButton alloc] init];
//
//    movableButton.frame=CGRectMake(DEF_SCREEN_WIDTH - 50, DEF_SCREEN_HEIGHT - 50 - 64 - 49, 50, 50);
//
//    //点击事件
//    [movableButton addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
//
//    //圆角
//    movableButton.layer.cornerRadius=25;
//    movableButton.layer.masksToBounds=YES;
//
//    //按钮图片
////    [movableButton setImage:[UIImage imageNamed:@"yue"] forState:UIControlStateNormal];
//    [movableButton setTitle:@"客服" forState:UIControlStateNormal];
//    [movableButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//
//    [self.window addSubview:movableButton];
    
    return YES;
}
- (void)buttonClick{
    
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
    if (result)
    {//友盟分享配置
        return result;
    }else
    {//支付宝和微信配置
        
        return [WXApi handleOpenURL:url delegate:self];
        
    }
    
}


// NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
    if (result)
    {//友盟配置
        return result;
    }else{
        
        return [WXApi handleOpenURL:url delegate:self];
    }
    return YES;
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
